package com.example.web.controller;

import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.example.web.entity.User;
import com.example.web.service.IUserService;

@RestController
@RequestMapping("/web/user")
public class UserController {
    @Autowired
    IUserService userService;
 
    @RequestMapping("/save")
    public String save(){
        User user2 = new User();
        for (int i = 0; i < 40; i++) {
            user2.setId((long)i);
            user2.setUserId((long)i);
            Random r = new Random();
            user2.setOrderId((long)r.nextInt(100));
            user2.setNickName("owenma"+i);
            user2.setPassWord("password"+i);
            user2.setUserName("userName"+i);
            userService.insert(user2);
        }
        return "success";
    }
 
    @RequestMapping("/findAll")
    public String findAll(){
        Wrapper<User> userWrapper = new Wrapper<User>() {
            /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
            public String getSqlSegment() {
                return "order by order_id desc";
            }
        };
        return JSONObject.toJSONString(userService.selectList(userWrapper));
    }
}
